package com.example.kotlindemo620

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import okhttp3.OkHttpClient
import okhttp3.Request

class HomeFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment_home, container, false)

        view.findViewById<View>(R.id.btn_live_request).setOnClickListener {
            Thread {
                try {
                    val client = OkHttpClient()
                    val request = Request.Builder()
                        .url("https://e.weather.com.cn/news/live.shtml")
                        .build()
                    client.newCall(request).execute().use { response ->
                        // 处理响应（可选）
                    }
                } catch (e: Exception) {
                    e.printStackTrace()
                }
            }.start()
        }
        return view
    }
}